<?php
include("inc/class.otr.php");
$otr = new OTR();

if(!$otr->checkLogin()){
	header("Location: index.php");
}

$showAdd = false;
$targetPage = 'projectov.php';

switch($_REQUEST['mode']){
	case 'admin':
		$projects = $otr->getProjects();
		$showAdd = true;
		$targetPage = 'project.php';
		break;
	case 'active':
		$projects = $otr->getActiveProjects();
		break;
	default:
		$projects = $otr->getActiveProjects();
		break;
}


?>
<div id="projects" style="float: left;">
	Projects
<?php
	foreach($projects as $p){
?>
	<div class="menuitem" onclick="loadProject(<?php echo($p['id']);?>);">&gt; <?php echo($p['shortname']);?></div>
<?php
	}
	if($showAdd){
?>
		<div class="menuitem" onclick="loadProject(0);">Add new...</div>
<?php
	}
?>
</div>
<div id="pnlProject"  style="float: left;">
</div>
<script type="text/javascript">
	var loadProject = function(id){
		ajaxGet('<?php echo($targetPage);?>', 'id='+id, $('pnlProject'), null);
	}
</script>